/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import java.sql.*;
import java.util.Calendar;
import java.util.Vector;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpSession;

public class Sala {
    int sid;
    String naziv;
    String lokacija;
    int kapacitet;
    int brracunara;
    int imaTablu;
    int imaProjektor;
    String tabla;
    String projektor;

    boolean imaproj;
    boolean imatabla;


     public String promeni(){
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int tab=0,pro=0;tabla="не";projektor="не";
            if(imatabla){tab=1;tabla="да";}
            if(imaproj){pro=1;projektor="да";}
            String upit = "update sala set Kapacitet ='"+ kapacitet +"',"+
                        "BrRacunara ='"+ brracunara +"',"+
                        "ImaTablu ='"+ tab +"',"+
                        "ImaProjektor ='"+ pro +"'"+
                        "where naziv = '" + naziv + "';";
            stmt.executeUpdate(upit);
            stmt.close();con.close();
        }catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {}
            }
            context.addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return "error";
        }
        context.addMessage(null, new FacesMessage("Информације успешно промењене!"));
        return null;
   }


    public String lab25(){
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int salaid=1;
            rs = stmt.executeQuery("select * from sala where sid=" + salaid + ";");
            while(rs.next()){
                sid=1;
                naziv=rs.getString("naziv");
                lokacija=rs.getString("lokacija");
                kapacitet=rs.getInt("kapacitet");
                brracunara=rs.getInt("brracunara");
                imaTablu=rs.getInt("imaTablu");
                imaProjektor=rs.getInt("imaProjektor");
                if(imaTablu==1){tabla="Ima";}
                else{tabla="Nema";}
                if(imaProjektor==1){projektor="Ima";}
                else{projektor="Nema";}
           }
        } catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                }
            }
            String vrati="error";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return vrati;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        User u=(User)session.getAttribute("user");
        return u.klabkonkretna();
    }

    public String lab26(){
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int salaid=2;
            rs = stmt.executeQuery("select * from sala where sid=" + salaid + ";");
            while(rs.next()){
                sid=2;
                naziv=rs.getString("naziv");
                lokacija=rs.getString("lokacija");
                kapacitet=rs.getInt("kapacitet");
                brracunara=rs.getInt("brracunara");
                imaTablu=rs.getInt("imaTablu");
                imaProjektor=rs.getInt("imaProjektor");
                if(imaTablu==1){tabla="Ima";}
                else{tabla="Nema";}
                if(imaProjektor==1){projektor="Ima";}
                else{projektor="Nema";}
            }
            
        } catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                }
            }
            String vrati="error";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return vrati;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        User u=(User)session.getAttribute("user");
        return u.klabkonkretna();

    }
    public String lab60(){
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int salaid=3;
            rs = stmt.executeQuery("select * from sala where sid=" + salaid + ";");
            while(rs.next()){
                sid=3;
                naziv=rs.getString("naziv");
                lokacija=rs.getString("lokacija");
                kapacitet=rs.getInt("kapacitet");
                brracunara=rs.getInt("brracunara");
                imaTablu=rs.getInt("imaTablu");
                imaProjektor=rs.getInt("imaProjektor");
                if(imaTablu==1){tabla="Ima";}
                else{tabla="Nema";}
                if(imaProjektor==1){projektor="Ima";}
                else{projektor="Nema";}
            }
        } catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                }
            }
            String vrati="error";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return vrati;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        User u=(User)session.getAttribute("user");
        return u.klabkonkretna();

    }
    public String lab61(){
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int salaid=5;
            rs = stmt.executeQuery("select * from sala where sid=" + salaid + ";");
            while(rs.next()){
                sid=5;
                naziv=rs.getString("naziv");
                lokacija=rs.getString("lokacija");
                kapacitet=rs.getInt("kapacitet");
                brracunara=rs.getInt("brracunara");
                imaTablu=rs.getInt("imaTablu");
                imaProjektor=rs.getInt("imaProjektor");
                if(imaTablu==1){tabla="Ima";}
                else{tabla="Nema";}
                if(imaProjektor==1){projektor="Ima";}
                else{projektor="Nema";}
            }
        } catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                }
            }
            String vrati="error";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return vrati;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        User u=(User)session.getAttribute("user");
        return u.klabkonkretna();

    }
        public String alab25(){
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int salaid=1;
            rs = stmt.executeQuery("select * from sala where sid=" + salaid + ";");
            while(rs.next()){
                sid=1;
                naziv=rs.getString("naziv");
                lokacija=rs.getString("lokacija");
                kapacitet=rs.getInt("kapacitet");
                brracunara=rs.getInt("brracunara");
                imaTablu=rs.getInt("imaTablu");
                imaProjektor=rs.getInt("imaProjektor");
                if(imaTablu==1){tabla="Ima";}
                else{tabla="Nema";}
                if(imaProjektor==1){projektor="Ima";}
                else{projektor="Nema";}
            }
        } catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                }
            }
            String vrati="error";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return vrati;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        User u=(User)session.getAttribute("user");
        return u.alabkonkretna();
    }

    public String alab26(){
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int salaid=2;
            rs = stmt.executeQuery("select * from sala where sid=" + salaid + ";");
            while(rs.next()){
                sid=2;
                naziv=rs.getString("naziv");
                lokacija=rs.getString("lokacija");
                kapacitet=rs.getInt("kapacitet");
                brracunara=rs.getInt("brracunara");
                imaTablu=rs.getInt("imaTablu");
                imaProjektor=rs.getInt("imaProjektor");
                if(imaTablu==1){tabla="Ima";}
                else{tabla="Nema";}
                if(imaProjektor==1){projektor="Ima";}
                else{projektor="Nema";}
            }
        } catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                }
            }
            String vrati="error";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return vrati;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        User u=(User)session.getAttribute("user");
        return u.alabkonkretna();

    }
    public String alab60(){
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int salaid=3;
            rs = stmt.executeQuery("select * from sala where sid=" + salaid + ";");
            while(rs.next()){
                sid=3;
                naziv=rs.getString("naziv");
                lokacija=rs.getString("lokacija");
                kapacitet=rs.getInt("kapacitet");
                brracunara=rs.getInt("brracunara");
                imaTablu=rs.getInt("imaTablu");
                imaProjektor=rs.getInt("imaProjektor");
                if(imaTablu==1){tabla="Ima";}
                else{tabla="Nema";}
                if(imaProjektor==1){projektor="Ima";}
                else{projektor="Nema";}
            }
        } catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                }
            }
            String vrati="error";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return vrati;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        User u=(User)session.getAttribute("user");
        return u.alabkonkretna();

    }
    public String alab61(){
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int salaid=5;
            rs = stmt.executeQuery("select * from sala where sid=" + salaid + ";");
            while(rs.next()){
                sid=5;
                naziv=rs.getString("naziv");
                lokacija=rs.getString("lokacija");
                kapacitet=rs.getInt("kapacitet");
                brracunara=rs.getInt("brracunara");
                imaTablu=rs.getInt("imaTablu");
                imaProjektor=rs.getInt("imaProjektor");
                if(imaTablu==1){tabla="Ima";}
                else{tabla="Nema";}
                if(imaProjektor==1){projektor="Ima";}
                else{projektor="Nema";}
            }
            FacesContext context = FacesContext.getCurrentInstance();
            HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
            session.setAttribute("laboratory",this);
            stmt.close();
            con.close();
        } catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                }
            }
            String vrati="error";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return vrati;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        User u=(User)session.getAttribute("user");
        return u.alabkonkretna();

    }

     public String lab25tabela(){
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        try {
            con = DB.getConnection();
            stmt = con.createStatement();
            int salaid=1;
            rs = stmt.executeQuery("select * from sala where sid=" + salaid + ";");
            while(rs.next()){
                sid=1;
                naziv=rs.getString("naziv");
                lokacija=rs.getString("lokacija");
                kapacitet=rs.getInt("kapacitet");
                brracunara=rs.getInt("brracunara");
                imaTablu=rs.getInt("imaTablu");
                imaProjektor=rs.getInt("imaProjektor");
                if(imaTablu==1){tabla="Ima";}
                else{tabla="Nema";}
                if(imaProjektor==1){projektor="Ima";}
                else{projektor="Nema";}
            }
            FacesContext context = FacesContext.getCurrentInstance();
            HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
            session.setAttribute("laboratory",this);
        } catch (Exception e) {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                }
            }
            String vrati="error";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getLocalizedMessage()));
            return vrati;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        User u=(User)session.getAttribute("user");
        return u.alabkonkretna();
    }


    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }
    public boolean getImaproj() {
        return imaproj;
    }

    public void setImaproj(boolean imaproj) {
        this.imaproj = imaproj;
    }
    public boolean getImatabla() {
        return imatabla;
    }

    public void setImatabla(boolean imatabla) {
        this.imatabla = imatabla;
    }

   public String getNaziv() {
        return naziv;
    }

    public void setNaziv(String naziv) {
        this.naziv = naziv;
    }

    public String getTabla() {
        return tabla;
    }

    public void setTabla(String tabla) {
        this.tabla = tabla;
    }
    public String getProjektor() {
        return projektor;
    }

    public void setProjektor(String projektor) {
        this.projektor = projektor;
    }

    public String getLokacija() {
        return lokacija;
    }

    public void setLokacija(String lokacija) {
        this.lokacija = lokacija;
    }

    public int getKapacitet() {
        return kapacitet;
    }

    public void setKapacitet(int kapacitet) {
        this.kapacitet = kapacitet;
    }

    public int getBrracunara() {
        return brracunara;
    }

    public void setBrracunara(int brracunara) {
        this.brracunara = brracunara;
    }

}
